﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using HWR_Ants.Classes;

namespace HWR_Ants.Forms
{
    public partial class fHWR_Ants : Form
    {
        private TSP_File tspFile;

        public fHWR_Ants()
        {
            InitializeComponent();
            openFileDialog1.InitialDirectory = Application.StartupPath;
            openFileDialog1.RestoreDirectory = true;

            /*
            SortedList<string, Point> ls = new SortedList<string, Point>();
            Point[] p = new Point[5];
            ls.Add("1", p[0]);
            ls.Add("2", p[1]);
            ls.Add("3", p[2]);
            ls.Add("4", p[3]);

            p[0] = new Point(10, 100);
            p[1] = new Point(274, 242);
            p[2] = new Point(345, 353);
            p[3] = new Point(428, 285);
            p[4] = new Point(534, 205);

            string city_1 = "{X=10,Y=100}";
            string city_2 = "{X=274,Y=242}";
            string city_3 = "{X=345,Y=353}";
            string city_4 = "{X=428,Y=285}";
            string city_5 = "{X=534,Y=205}";



            WorldBuilder wb = new WorldBuilder();
            City City_1 = wb.AddCity(city_1);
            City City_2 = wb.AddCity(city_2);
            City City_3 = wb.AddCity(city_3);
            City City_4 = wb.AddCity(city_4);
            City City_5 = wb.AddCity(city_5);
            wb.AddRoad(Distance(p[0], p[1]), City_1, City_2);
            wb.AddRoad(Distance(p[0], p[2]), City_1, City_3);
            wb.AddRoad(Distance(p[0], p[3]), City_1, City_4);
            wb.AddRoad(Distance(p[0], p[4]), City_1, City_5);
            wb.AddRoad(Distance(p[1], p[2]), City_2, City_3);
            wb.AddRoad(Distance(p[1], p[3]), City_2, City_4);
            wb.AddRoad(Distance(p[1], p[4]), City_2, City_5);
            wb.AddRoad(Distance(p[2], p[3]), City_3, City_4);
            wb.AddRoad(Distance(p[2], p[4]), City_3, City_5);
            wb.AddRoad(Distance(p[3], p[4]), City_4, City_5);
            RoadMap rm = new RoadMap(wb);
            rm.UpdateEvent += new RoadMap.UpdateEventHandler(tempUpdate);
            IEnumerable<City> temp  = rm.FindTour();

            MessageBox.Show("huhu");
            ;
            */
            // Tour t = new Tour(ls.Values, Tools.Tools.getCurrentStoredOptions());
            // t.StartTour();
        }

        /*
        void tempUpdate(RoadMap sender, UpdateEventArgs e)
        {
            MessageBox.Show(e.ToString());
        }

        private static double Distance(Point p1, Point p2) 
        {
            return Math.Sqrt(Math.Pow((p1.X - p2.X), 2) + Math.Pow((p1.Y - p2.Y), 2));
        }
        */
        private void öffnenToolStripMenuItem_Click(object sender, EventArgs e)
        {

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if (openFileDialog1.FileName.Contains("\\"))
                    openFileDialog1.InitialDirectory = openFileDialog1.FileName.Substring(0, openFileDialog1.FileName.LastIndexOf("\\"));
                
                if (File.Exists(openFileDialog1.FileName))
                {
                    try
                    {
                        tspFile = new TSP_File(openFileDialog1.FileName);
                        fTSP_Painting tsp = new fTSP_Painting();
                        tsp.TspFileToPaint = tspFile;
                        tsp.Show();
                    }
                    catch (Exception ex)
                    {
                        tspFile = null;
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }

        private void einstellungenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            fOptions fo = new fOptions();
            fo.Show();
        }

        private void ausgbToolStripMenuItem_Click(object sender, EventArgs e)
        {
            fAusgabe fa = new fAusgabe();
            fa.Show();
        }

        private void hilfeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            fAbout fa = new fAbout();
            fa.Show();
        }

        private void bt_Start_Click(object sender, EventArgs e)
        {
            if (bt_Start.Text == "Start")
            {
                bt_Start.Text = "Stopp";
            }
            else
            {
                bt_Start.Text = "Start";
            }
        }
    }
}
